//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: baseJs.imgUrl,
    pageIndex: 1,
    state: "",
    listData: [],
    needMoney: "",
    // 
    uid:"",
    userType:"",

  },

 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      uid: wx.getStorageSync('uid'),
      userType: wx.getStorageSync('userType')
    })
    this.GetMyAttractInvestmentList();
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.data.pageIndex++;
    this.GetMyAttractInvestmentList();

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  // GetMyAttractInvestmentList
  GetMyAttractInvestmentList: function() {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var listData = this.data.listData;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetMyAttractInvestmentList&UID=" + uid + "&PageSize=10&PageIndex=" + pageIndex),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          listData.push(json[i])
        }
        that.setData({
          listData: listData,
        })
        console.log(listData);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
      }
    })
  },
  // del
  del: function(e) {
    var that = this;
    var uid = this.data.uid;
    wx.showModal({
      title: '提示',
      content: '确认删除该招商信息?',
      success: function(res) {
        if (res.confirm) {
          // console.log('用户点击确定');
          wx.request({
            url: baseJs.api + baseJs.encryUrl("method=DeleteMyAttractInvestment&InvestId=" + e.currentTarget.dataset.id + "&UID=" + uid),
            success: function(res) {
              if (JSON.parse(baseJs.decryUrl(res.data)).ResultFlag == 1) {
                wx.showToast({
                  title: JSON.parse(baseJs.decryUrl(res.data)).ResultMsg,
                  icon: 'none',
                  duration: 2000
                });
                that.setData({
                  pageIndex:1,
                  listData: [],
                })
                that.GetMyAttractInvestmentList();
              } else {
                wx.showToast({
                  title: JSON.parse(baseJs.decryUrl(res.data)).ResultMsg,
                  icon: 'none',
                  duration: 2000
                });
              }
            }
          })
        } else if (res.cancel) {
          // console.log('用户点击取消');
        }
      }
    })
  },
  // 
})